#!/usr/bin/env python
# -*- coding: UTF-8 -*-  

#--------- 外部模块处理<<开始>> ---------#

#-----系统自带必备模块引用-----

import sys # 操作系统模块


#-----系统外部需安装库模块引用-----
from bs4 import BeautifulSoup


#--------- 内部模块处理<<开始>> ---------#

# 版本说明
def version(dic_p={}):

    print ("\n")
    print ("-----------------------------")
    [print("\n",x," --- ",str(dic_p[x]).replace("[","").replace("]","").replace("'",""),"\n") for x in dic_p] # 调试用
    print ("-----------------------------")

# 核心类
class Prompt():

    # 抽取标注
    def extract_mark(self,**kwargs):
    
        list_t = []
    
        result_p = kwargs.get("dic_mark",{})
        
        if (result_p == {}):
        
            print ("抽取标注结果字典为空")
            
            return result_p
        
        html_content = kwargs.get("html_content","").strip()
        
        if (html_content == ""):
        
            print ("抽取标注输入为空")
            
            return result_p 
        
        soup = BeautifulSoup(html_content, 'html.parser')
            
        # 抽取P语言关键标签
        for x in result_p:
            
            list_t = soup.find_all(x)
            
            for y in list_t:
                
                result_p[x].append(str(y).replace("<" + x + ">","").replace("</" + x + ">","")) 
            
        return result_p


#--------- 内部模块处理<<结束>> ---------#

#---------- 主过程<<开始>> -----------#

def main():
    
    result_p = {}
    
    # 说明字典
    dic_note = {
    "版权":["丽垚人工智能工作室"],
    "作者":["集体","吉更"],
    "初创时间":["2025年5月"],
    "功能":"P语言主处理",
    "版本":"1.0.1"
    }
    
    version(dic_p=dic_note) # 打印版本
    
    dic_mark = {
    "role":[],
    "bg":[],
    "aim":[],
    "add":[]
    }
    
    html_content = """
    
    你是一位<role>现代诗人</role>，<bg>用比喻手法</bg><aim>写一首自由诗</aim>，<bg>主题是‘友谊像一杯茶’</bg>，
    <bg>语言简洁且有画面感。</bg>
    <add>行数不要超过8行</add>
    
    """
    
    print("\n",html_content,"\n")
    
    # 提示词类实例化
    prompt = Prompt()
    
    result_p = prompt.extract_mark(dic_mark=dic_mark, html_content=html_content)
    
    for x in result_p:
    
        print(x,result_p[x],"\n")

if __name__ == "__main__":
    
    main()
    
#---------- 主过程<<结束>> -----------#